#!/usr/bin/env python3
"""
这个脚本用于修复visualization.py中虚拟通道的日志问题，将日志记录修改为界面显示
"""

import re

def main():
    # 读取visualization.py文件内容
    with open('visualization.py', 'r', encoding='utf-8') as f:
        content = f.read()
    
    # 修改虚拟通道日志记录，约在1370-1380行
    pattern = r'# 获取虚拟通道\s+virtual_channel = .*?logger\.warning\(\s+f"发现未知虚拟通道.*?\)\s+virtual_channel = "未知虚拟通道"'
    replacement = '# 获取虚拟通道\n                vc_value = (virtual_channel_frame_count_high >> 6) & 0x03\n                if vc_value == 0:\n                    virtual_channel = "VC0"\n                elif vc_value == 1:\n                    virtual_channel = "VC1"\n                elif vc_value == 2:\n                    virtual_channel = "VC2"\n                elif vc_value == 3:\n                    virtual_channel = "VC3"\n                else:\n                    # 直接在状态文本中显示具体虚拟通道值，不写入日志\n                    virtual_channel = f"未知虚拟通道(0x{vc_value:X})"'
    
    content = re.sub(pattern, replacement, content, flags=re.DOTALL)
    
    # 保存修改后的内容
    with open('visualization.py', 'w', encoding='utf-8') as f:
        f.write(content)
    
    print("修复完成：虚拟通道日志记录已改为界面显示")

if __name__ == "__main__":
    main() 